//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {
	var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	//获取用户列表
	var $url_get_users = $base_url + "/admin/user/v1/getUsers";
	var $url_get_inviteUsers = $base_url + "/admin/user/v1/getInviteUsers";
	var $url_get_users_2_ad = $base_url + "/admin/user/v1/getUsers2Ad";
	var $url_get_userInfo = $base_url + "/admin/user/v1/getInfo";
	
	
	//获取关注
	var $url_get_follows = $base_url + "/admin/user/v1/getFollows";
	var $url_get_fans = $base_url + "/admin/user/v1/getFans";
	return {
		getUsers: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_users, {
						key: params.key,
						letter: params.letter,
						atIds: params.atIds,
						page: params.page,
						pagesize: params.pagesize
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getUsers2Ad: function(key) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_users_2_ad, {
						key: key
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		//用户详情
		getUserInfo: function(uid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_userInfo, {
						uid: uid
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		//邀请用户信息
		getInviteUsers: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_inviteUsers, {
						page: params.page,
						pagesize: params.pagesize
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		//获取关注
		getFollows: function(userId, page, pagesize) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_follows, {
						userId: userId,
						page: page,
						pagesize: pagesize
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		//获取粉丝
		getFans: function(userId, page, pagesize) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_fans, {
						userId: userId,
						page: page,
						pagesize: pagesize
					}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
	}
}